package com.example.bili.adapter;

import android.content.Context;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.bili.R;
import com.example.bili.allbean.PartitionLiveBean;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;


/**
 * Created by nange on 2017/3/13.
 */

public class PartitionLiveAdapter extends RecyclerView.Adapter<PartitionLiveAdapter.VHolder> {
    Context context;
    private List<PartitionLiveBean.DataBean.EntranceIconsBean> entranceIcons;
    private List<PartitionLiveBean.DataBean.PartitionsBean> partitions;

    public PartitionLiveAdapter(Context context, List<PartitionLiveBean.DataBean.EntranceIconsBean> entranceIcons, List<PartitionLiveBean.DataBean.PartitionsBean> partitions) {
        this.context = context;
        this.entranceIcons = entranceIcons;
        this.partitions = partitions;
    }

    @Override
    public VHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        VHolder vHolder = new VHolder(LayoutInflater.from(context).inflate(R.layout.partition_live_item, null));

        return vHolder;
    }

    @Override
    public void onBindViewHolder(VHolder holder, int position) {

        if (position <= 4) {
            holder.l_partition_fqlive_leftimg.setImageURI(entranceIcons.get(position).getEntrance_icon().getSrc());
            holder.l_partition_fqlive_lefttitle.setText(entranceIcons.get(position).getName());
            holder.l_partition_fqlivesiza_righttv.setText(partitions.get(position).getPartition().getCount() + "个直播");

            holder.l_live_item_img1.setImageURI(Uri.parse(partitions.get(position).getLives().get(0).getCover().getSrc()));
            holder.l_live_item_img2.setImageURI(Uri.parse(partitions.get(position).getLives().get(1).getCover().getSrc()));
            holder.l_live_item_img3.setImageURI(Uri.parse(partitions.get(position).getLives().get(2).getCover().getSrc()));
            holder.l_live_item_img4.setImageURI(Uri.parse(partitions.get(position).getLives().get(3).getCover().getSrc()));
            holder.l_live_item_title1.setText(partitions.get(position).getLives().get(0).getTitle());
            holder.l_live_item_title2.setText(partitions.get(position).getLives().get(1).getTitle());
            holder.l_live_item_title3.setText(partitions.get(position).getLives().get(2).getTitle());
            holder.l_live_item_title4.setText(partitions.get(position).getLives().get(3).getTitle());
            holder.l_live_item_yuanimg1.setImageURI(Uri.parse(partitions.get(position).getLives().get(0).getCover().getSrc()));
            holder.l_live_item_yuanimg2.setImageURI(Uri.parse(partitions.get(position).getLives().get(1).getCover().getSrc()));
            holder.l_live_item_yuanimg3.setImageURI(Uri.parse(partitions.get(position).getLives().get(2).getCover().getSrc()));
            holder.l_live_item_yuanimg4.setImageURI(Uri.parse(partitions.get(position).getLives().get(3).getCover().getSrc()));
        }


    }

    @Override
    public int getItemCount() {
        return partitions.size();
    }

    public class VHolder extends RecyclerView.ViewHolder {

        private final SimpleDraweeView l_partition_fqlive_leftimg;
        private final TextView l_partition_fqlive_lefttitle;
        private final TextView l_partition_fqlivesiza_righttv;


        private final TextView l_live_item_title1;
        private final TextView l_live_item_title2;
        private final TextView l_live_item_title3;
        private final TextView l_live_item_title4;
        private final SimpleDraweeView l_live_item_img1;
        private final SimpleDraweeView l_live_item_img2;
        private final SimpleDraweeView l_live_item_img3;
        private final SimpleDraweeView l_live_item_img4;
        private final SimpleDraweeView l_live_item_yuanimg1;
        private final SimpleDraweeView l_live_item_yuanimg2;
        private final SimpleDraweeView l_live_item_yuanimg3;
        private final SimpleDraweeView l_live_item_yuanimg4;


        public VHolder(View itemView) {
            super(itemView);
            l_partition_fqlive_leftimg = (SimpleDraweeView) itemView.findViewById(R.id.l_partition_fqlive_leftimg);
            l_partition_fqlive_lefttitle = (TextView) itemView.findViewById(R.id.l_partition_fqlive_lefttitle);
            l_partition_fqlivesiza_righttv = (TextView) itemView.findViewById(R.id.l_partition_fqlivesiza_righttv);
            l_live_item_img1 = (SimpleDraweeView) itemView.findViewById(R.id.l_live_item_img1);
            l_live_item_img2 = (SimpleDraweeView) itemView.findViewById(R.id.l_live_item_img2);
            l_live_item_img3 = (SimpleDraweeView) itemView.findViewById(R.id.l_live_item_img3);
            l_live_item_img4 = (SimpleDraweeView) itemView.findViewById(R.id.l_live_item_img4);

            l_live_item_title1 = (TextView) itemView.findViewById(R.id.l_live_item_title1);
            l_live_item_title2 = (TextView) itemView.findViewById(R.id.l_live_item_title2);
            l_live_item_title3 = (TextView) itemView.findViewById(R.id.l_live_item_title3);
            l_live_item_title4 = (TextView) itemView.findViewById(R.id.l_live_item_title4);
            l_live_item_yuanimg1 = (SimpleDraweeView) itemView.findViewById(R.id.l_live_item_yuanimg1);
            l_live_item_yuanimg2 = (SimpleDraweeView) itemView.findViewById(R.id.l_live_item_yuanimg2);
            l_live_item_yuanimg3 = (SimpleDraweeView) itemView.findViewById(R.id.l_live_item_yuanimg3);
            l_live_item_yuanimg4 = (SimpleDraweeView) itemView.findViewById(R.id.l_live_item_yuanimg4);

        }
    }
}
